package ar.republicagroup.gestion.util.helpers;

import com.toedter.calendar.JDateChooser;
import java.awt.Component;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Date;
import javax.swing.AbstractCellEditor;
import javax.swing.DefaultCellEditor;
import javax.swing.JTable;
import javax.swing.table.TableCellEditor;
import org.apache.log4j.Logger;


public class JCalendarCellEditor extends AbstractCellEditor implements TableCellEditor,PropertyChangeListener {
    AbstractCellEditor editor = null;
    JDateChooser calendario;
    Date fecha;
    
    Logger log = Logger.getLogger(JCalendarCellEditor.class);
    
    public JCalendarCellEditor() {
       log.info("CONTRUCTOR JCalendarCellEditor");
       calendario = new JDateChooser();
       calendario.setName("Mi primer calendar");
       fecha = new Date();
    }

   
    

    @Override
    public Object getCellEditorValue() {
       return fecha;
    }

    @Override
    public JDateChooser getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
        log.info("GENERANDO CALENDAR CELL EDITOR");
        System.out.println(fecha);
        calendario.addPropertyChangeListener(this);
        calendario.setName("Te cambie el nombre");
        calendario.setDate(fecha);
        return calendario;
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if(evt.getPropertyName().equals("date")){
          log.info(fecha);
          log.info("UN NUEVO DIA: "+evt.getNewValue());
          log.info(calendario.getName());
          calendario.setName("RADIOHEAD");
          fecha = (Date)evt.getNewValue();
          System.out.println("FECHITA NUEVA: "+fecha);
          System.out.println("CALENDAR DATE "+calendario.getDate());
         
//          Date diaNuevo = new Date();
//          calendario.setDate(diaNuevo);
      }
    }
   
}
